<template>
  <div class="goods">
    <div class="goods-wrap">
      <div class="header">
        <div class="header-left">
          <h3>
            <span @click="toItem">{{ newItemList.name }}</span>
          </h3>
        </div>
        <div class="header-right">
          <ul>
            <li
              v-for="item in newItemList.subCateList.slice(0, 7)"
              :key="item.id"
            >
              <span class="right-text">{{ item.name }}</span>
              <span class="right-span">/</span>
            </li>
          </ul>
          <span href="#">更多新品 ></span>
        </div>
      </div>
      <div class="goods-banner">
        <img :src="newItemList.bannerUrl" alt="" />
      </div>
      <div class="goods-mains" @click="toDetail">
        <div
          class="body-item"
          v-for="item in newItemList.itemList"
          :key="item.id"
        >
          <div class="store-img">
            <img class="img" :src="item.showPicUrl" alt="" />
            <img
              class="img-hidden"
              :src="item.scenePicUrl"
              alt=""
              :data-id="item.id"
            />
          </div>
          <span class="store-introduce" :data-id="item.id">
            {{ item.name }}
          </span>
          <p class="store-price">
            <span class="price-height">¥199</span>
            <span class="price-low">¥399</span>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Goods',
  props: {
    itemList: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      // 当前页面需要渲染的数据
      newItemList: {},
    }
  },
  methods: {
    // 跳转到对应的商品详情页
    toDetail(event) {
      this.$emit('toDetail', event)
    },
    // 跳转到对应的item页面
    toItem() {
      this.$router.history.push({
        path: '/item',
        query: {
          categoryId: this.newItemList.id,
        },
      })
    },
  },
  watch: {
    itemList: {
      handler(itemList) {
        this.newItemList = itemList
      },
      immediate: true,
    },
  },
}
</script>

<style lang="less" scoped>
.goods {
  width: 100%;
  margin-top: 50px;
  // border: 1px solid pink;
  .goods-wrap {
    margin: 0 auto;
    width: 1090px;
    // border: 1px solid green;
  }
}
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding-bottom: 30px;
  .header-left {
    display: flex;
    align-items: flex-end;
    h3 {
      font-size: 28px;
      margin-right: 20px;
      span {
        text-decoration: none;
        color: #333;
      }
      span:hover {
        color: #e2c199 !important;
      }
    }
    p {
      font-size: 14px;
      padding-bottom: 3px;
    }
  }
  .header-right {
    padding-bottom: 3px;
    display: flex;
    span {
      text-decoration: none;
      font-size: 14px;
      color: #333;
    }
    span:hover {
      color: #e2c199 !important;
    }
    ul {
      display: flex;
      li {
        text-decoration: none;
        font-size: 14px;
        color: #333;
        .right-text {
          padding: 0 10px;
        }
        .right-text:hover {
          color: #e2c199 !important;
        }
        &:last-child {
          margin-right: 30px;
          .right-span {
            display: none;
          }
        }
      }
    }
  }
}
.goods-banner {
  width: 1090px;
  height: 310px;
  img {
    height: 100%;
    width: 100%;
  }
}
.goods-mains {
  display: flex;
  justify-content: space-between;
  padding-top: 30px;
}
.body-item {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  .store-img {
    position: relative;
    width: 265px;
    height: 265px;
    background-color: #f4f4f4;
    .img,
    .img-hidden {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
    }
    .img-hidden {
      display: none;
    }
  }

  .store-introduce {
    display: block;
    text-align: center;
    margin-top: 20px;
    color: #333;
    font-size: 13px;
    font-weight: bold;
    width: 160px;
    &:hover {
      color: #d2b074;
    }
  }
  .store-price {
    padding-bottom: 5px;
    .price-height {
      color: #d4282d;
      font-size: 13px;
      margin-right: 5px;
    }
    .price-low {
      text-decoration: line-through;
      color: #999;
      font-size: 10px;
    }
  }
}
.body-item:hover {
  background-color: #f4f0ea;
  .img-hidden {
    display: block;
  }
  .img {
    display: none;
  }
}
</style>
